package com.sinopec.basemodule.lifecycle

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver

class LifecycleExtension {
}

/**
 * 达到这个状态就会执行
 */
fun Lifecycle.onState(
    vararg statePair: Pair<Lifecycle.Event, () -> Unit>
) {
    val stateMapping = statePair.toMap()
    addObserver(LifecycleEventObserver { source, event ->
        stateMapping[event]?.invoke()
    })
}